package com.joke.handler;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.widget.Toast;
import com.joke.JokeList;
import com.joke.R;
import com.joke.model.Constants;

public class JokeHandler extends Handler{

	private Context mContext;
	
	public JokeHandler() {
		super();
	}

	public JokeHandler(Looper looper,Context context) {
		super(looper);
		mContext = context;
	}

	@Override
	public void handleMessage(Message msg) {
		try{
			int reCode = Constants.update();
			switch(reCode){
				/**获取列表成功**/
				case 200:
					 Intent intent = new Intent();
				     intent.setClass(mContext, JokeList.class);
				     mContext.startActivity(intent);
					break;
				/**不能连接服务器**/
				case 1:
					Toast.makeText(mContext, mContext.getString(R.string.disconnect), Toast.LENGTH_LONG).show();
					break;
				/**获取列表异常**/
				case -1:
					Toast.makeText(mContext, mContext.getString(R.string.disconnect), Toast.LENGTH_LONG).show();
					break;
				default:
					break;
			}
    	}catch(Exception ex){
    		ex.printStackTrace();
    	}
	}
	
}
